﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_Server.App1AppHandler
{
    public class BankerItems
    {
        public List<Loot> BankItems = new List<Loot>();
        public List<Loot> PlayerItems = new List<Loot>();
        public int BankerCoins = 0;
        public int PlayerCoins = 0;

        public string toXML(Character sendingToCharacter)
        {
            string result = "";
            string innerXML = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("bankeritems");

            xmldoc.WriteAttributeString("BankerCoins", BankerCoins.ToString());
            xmldoc.WriteAttributeString("PlayerCoins", PlayerCoins.ToString());

            xmldoc.WriteStartElement("BankItems");
            innerXML = "";
            foreach (Loot loot in BankItems)
            {
                innerXML = innerXML + loot.toXML(sendingToCharacter);
            }
            if (innerXML != "") xmldoc.WriteRaw(innerXML);
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("PlayerItems");
            innerXML = "";
            foreach (Loot loot in PlayerItems)
            {
                innerXML = innerXML + loot.toXML(sendingToCharacter);
            }
            if (innerXML != "") xmldoc.WriteRaw(innerXML);
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
